<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增奖品')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-prize-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">奖品名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('prize_type')}">
                        <input type="radio" th:id="${'type_' + dict.dictCode}" name="type"
                               th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'type_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">奖品总数：</label>
                <div class="col-sm-8">
                    <input name="sumNum" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <div class="radio-box" th:each="dict : ${@dict.getType('prize_status')}">
                            <input type="radio" th:id="${'status_' + dict.dictCode}" name="status"
                                   th:value="${dict.dictValue}" th:checked="${dict.default}">
                            <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">概率：</label>
                <div class="col-sm-8">
                    <input name="probability" class="form-control" type="text">
                </div>
            </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">奖品图标：</label>
                    <div class="col-sm-8">
                        <button type="button" class="layui-btn" id="upload_main">上传图片</button>
                        <div class="layui-upload-list">
                            <input type="hidden" id="mainUrl" name="icon">
                            <p id="show_main"></p>
                        </div>
                    </div>
                </div>
                <div id="showCionNum" class="form-group" style="display:none;">
                    <label class="col-sm-3 control-label">智通币数量：</label>
                    <div class="col-sm-8">
                        <input name="coinNum" class="form-control" type="text">
                    </div>
                </div>
            <div id="showYH" class="form-group">
                <label class="col-sm-3 control-label">优惠券：</label>
                <div class="col-sm-8">
                    <select  name="resId" class="form-control m-b">
                        <option value="">请选择优惠券</option>
                        <option th:each="dict : ${yhList}" th:text="${dict.name}"
                                th:value="${dict.id}" required></option>
                    </select>
                </div>
            </div>
            <div id="showDK" class="form-group" style="display:none;">
                <label class="col-sm-3 control-label">抵扣券：</label>
                <div class="col-sm-8">
                    <select  name="resId" class="form-control m-b">
                        <option value="">请选择抵扣券</option>
                        <option th:each="dict : ${dkList}" th:text="${dict.name}"
                                th:value="${dict.id}" required></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "system/prize"
        $("#form-prize-add").validate({
            focusCleanup: true
        });

        $("input[type=radio][name=type]").on("ifChecked", function () {
            //不开启
            if ($(this).val() == 0) {
                //隐藏智通币
                $("#showCionNum").hide();
                //隐藏抵扣券
                $("#showDK").hide();
                //显示优惠券
                $("#showYH").show();
            } else if($(this).val() == 1){
                //隐藏智通币
                $("#showCionNum").hide();
                //显示抵扣券
                $("#showDK").show();
                //隐藏优惠券
                $("#showYH").hide();
            }else{
                //显示智通币
                $("#showCionNum").show();
                //隐藏抵扣券
                $("#showDK").hide();
                //隐藏优惠券
                $("#showYH").hide();
            }
        });


        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-prize-add').serialize());
            }
        }

        $("input[name='created']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });


        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;


            //普通图片上传
            upload.render({
                elem: '#upload_main'
                , url: ctx+'/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#show_main").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#mainUrl").val(res.url);
                }
            });

        })

    </script>
</body>
</html>